package com.foogui.primary.readwrite;

import java.util.HashMap;
import java.util.Map;

public class MyCache {
    private  volatile Map<String,Object> map=new HashMap<>();
    public void add(String key,Object object){
        System.out.println(Thread.currentThread().getName()+"正在写"+key);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        map.put(key, object);
        System.out.println(Thread.currentThread().getName()+"写完了"+key);
    }

    public Object get(String key){
        System.out.println(Thread.currentThread().getName()+"正在读"+key);
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }

        System.out.println(Thread.currentThread().getName()+"读完了"+key);
        return map.get(key);
    }
}
